import { customRef } from "vue";

export function useDeBounced<T>(value:T,delay=1000,callback:Function){
    let timer:any=null;
    return customRef((track,trigger)=>{
        return {
        get(){
            return value;
        },
        set(newValue:T){
            clearTimeout(timer);
            timer =setTimeout(()=>{
                value=newValue
                callback(newValue)
            },delay)
        }
        }
    })
}